function getLayerByTitle({ map, title }) {
    /* 1、获取所有的图层 */
    let layers = map.getLayers().getArray()
    /* 2、遍历图层,获取title='vector的图层'  find */
    let target = layers.find(item => item.get("title") == title)
    return target;
}
function setPntStyle({
    radius = 10,
    fill = "#ff2d51",
    stroke = "#333",
    width = 2
}) {
    return new ol.style.Style({
        //形状
        image: new ol.style.Circle({
            radius,
            fill: new ol.style.Fill({
                color: fill
            }),
            stroke: new ol.style.Stroke({
                color: stroke,
                width
            }),
        })
    })
}
function setLineStyle({
    color = "#333",
    width = 3
}) {
    return new ol.style.Style({
        //边线颜色
        stroke: new ol.style.Stroke({
            color,
            width
        })
    })
}
function setAreaStyle({ fill = "#33333380", stroke = "#ff2d51", width = 1 }) {
    return new ol.style.Style({
        //填充色
        fill: new ol.style.Fill({
            color: fill,
        }),
        //边线颜色
        stroke: new ol.style.Stroke({
            color: stroke,
            width,
        })
    })
}

function getCoordinate(feature) {
    return feature.getGeometry().getCoordinates()
}
/* geojson ToGeoJSON */
function ToGeoJSON(obj) {
    /* obj=object|array */
    if (obj instanceof Array) {
        return new ol.format.GeoJSON().writeFeaturesObject(obj)
    } else {
        return new ol.format.GeoJSON().writeFeatureObject(obj)
    }
}
function JSONToFeature(data) {
    return new ol.format.GeoJSON().readFeatures(data);
}
export { setAreaStyle };
/* geojson数据转openlayers的要素 */